package liuhe;


import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Vector;

import liuhe.http.WeifengHttp;
import liuhe.manager.MergeManager;
import liuhe.thread.ACThread;
import liuhe.thread.CS2Thread;
import liuhe.thread.FuteThread;
import liuhe.thread.GutongThread;
import liuhe.thread.JiarunThread;
import liuhe.thread.MergeThread;
import liuhe.thread.ShiwanThread;
import liuhe.thread.TaiheThread;
import liuhe.thread.TianziThread;
import liuhe.thread.WBThread;
import liuhe.thread.WanliThread;
import liuhe.thread.WeifengThread;
import liuhe.thread.XJSThread;
import liuhe.thread.YingtaiThread;
import team.gl.nio.svr.NettyServer;


import java.io.*;
import java.util.ArrayList;
import java.util.List;
import org.json.JSONObject;

//public class LiuHe {
//    public static void main(String[] args) {
//        String fileName = "2025024.data";
//        File file = new File(fileName);
//
//        try {
//            // 读取文件内容
//            String content = readFirstLine(file);
//            
//            // 处理JSON内容
//            JSONObject json = new JSONObject(content);
//            processJson(json);
//            
//            // 写回文件
//            writeToFile(file, json.toString());
//            
//        } catch (FileNotFoundException e) {
//            System.err.println("文件未找到: " + e.getMessage());
//        } catch (IOException e) {
//            System.err.println("IO异常: " + e.getMessage());
//        } catch (Exception e) {
//            System.err.println("其他错误: " + e.getMessage());
//        }
//    }
//
//    private static String readFirstLine(File file) throws IOException {
//        try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
//            return reader.readLine();
//        }
//    }
//
//    private static void processJson(JSONObject json) {
//        List<String> keysToRemove = new ArrayList<>();
//        
//        // 遍历所有键值对
//        for (String key : json.keySet()) {
//            if (key.contains("2025-01-23")) {
//                keysToRemove.add(key);
//            }
//        }
//        
//        // 删除需要移除的键
//        for (String key : keysToRemove) {
//            json.remove(key);
//        }
//    }
//
//    private static void writeToFile(File file, String content) throws IOException {
//        try (BufferedWriter writer = new BufferedWriter(new FileWriter(file))) {
//            writer.write(content);
//        }
//    }
//}


public class LiuHe {
	
	public static MergeManager mergeManager = new MergeManager();
	public static Vector<String> allowedIps = new Vector<String>();
	public static  boolean blogTofile = false;
	public static PrintStream psFile = null;
	public static PrintStream psConsole = null;
	public static void main(String[] args){
		
		System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
		
		try {
			
			if(blogTofile == true) {
				try {
					// ����·��
					File dir = new File("log");
					if (dir.exists()) {
					} else {
						dir.mkdirs();
					}

					// ������ض����ļ�
					
					SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");// �������ڸ�ʽ
					
					psFile = new PrintStream("log/" + df.format(new Date())
								+ ".txt");
					
					
					psConsole = System.out;

					System.setOut(psFile);
					System.setErr(psFile);
				} catch (FileNotFoundException e) {
					e.printStackTrace();
				}
			}
			
			allowedIps.add("113.13.170.117");
			allowedIps.add("112.213.117.44");
			
			allowedIps.add("43.154.76.22");
			allowedIps.add("127.0.0.1");
			
			mergeManager.initCurrentData();
			
			mergeManager.initCurrentDataOld();
			
//			ACThread acThread = new ACThread();
//			acThread.start();
//
//			ShiwanThread shiwanThread = new ShiwanThread();
//			shiwanThread.start();
//			
//			WanliThread wanliThread = new WanliThread();
//			wanliThread.start();
//
//			WeifengThread wfThread = new WeifengThread();
//			wfThread.start();
//			
//			CS2Thread cs2Thread = new CS2Thread();
//			cs2Thread.start();
//			
//			XJSThread xjsThread = new XJSThread();
//			xjsThread.start();
//
//			
//			FuteThread futeThread = new FuteThread();
//			futeThread.start();
//
//
//
//			TaiheThread taiheThread = new TaiheThread();
//			taiheThread.start();
//			
//			JiarunThread jiarunThread = new JiarunThread();
//			jiarunThread.start();
//			
//			GutongThread gutongThread = new GutongThread();
//			gutongThread.start();
//			
//			YingtaiThread yingtaiThread = new YingtaiThread();
//			yingtaiThread.start();
//			
//			TianziThread tianziThread = new TianziThread();
//			tianziThread.start();
			
			MergeThread mergeThread = new MergeThread(mergeManager);
			mergeThread.start();
			
			new NettyServer().run();
			
		}catch(Exception e) {
			e.printStackTrace();
		}
		

	}

}
